package com.yilee.idouban.task;

import java.net.HttpURLConnection;
import java.util.HashMap;
import java.util.Map;

import android.util.Log;

import com.yilee.idouban.bean.Person;
import com.yilee.idouban.task.common.GenericTask;
import com.yilee.idouban.task.common.TaskParams;
import com.yilee.idouban.task.common.TaskResult;
import com.yilee.idouban.util.HttpRequestUtil;
import com.yilee.idouban.xml.service.SAXPraserService;

/**
 * 取得用户信息
 * 
 * @author yilee
 * 
 */
public class GetUserInfoTask extends GenericTask {

	private static final String TAG = "yilee_GetUserInfoTask";
	public Person p = null;

	@Override
	protected TaskResult _doInBackground(TaskParams... params) {

		TaskParams param = params[0];
		Map<String, String> map = new HashMap<String, String>();

		try {
			map.put("Authorization",
					"Bearer " + param.getString("access_token"));
			HttpURLConnection conn = HttpRequestUtil.sendGetRequest(
					param.getString("url"), null, map);
			conn.connect();
			p = SAXPraserService.getPersonFromXML(conn.getInputStream());
			conn.disconnect();
		} catch (Exception e) {
			Log.e(TAG, e.getMessage());
			return TaskResult.NETWORK_ERROR;
		}
		return TaskResult.OK;
	}

}
